/*
健康评估ajax获取指导意见
传进来的都是对象格式
author zjw
*/
/* eslint-disable */
import { submitHealth } from '@/api/assessQuestion';
export const ajaxSend = async function (values) {
  if (Object.prototype.toString.call(values) !== '[object Object]') {
    uni.showToast({ title: '格式错误', icon: 'none' });
    return false;
  }
  const filterValues = Object.keys(values).filter((item) => values[item] || values[item] === 0);
  let sendData = {};
  if (filterValues && filterValues.length > 0) {
    filterValues.forEach((item) => {
      sendData[item] = values[item];
    });
    uni.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 15000,
      mask: true
    });
    const patientId = wx.getStorageSync('assessPatientId');
    let { data } = await submitHealth(patientId, sendData);
    let obj = {};
    data = data.reduce((cur, next) => {
      obj[next.healthGuidances] ? '' : (obj[next.healthGuidances] = true && cur.push(next));
      return cur;
    }, []);
    uni.hideToast();
    return data;
  }
  return [];
};
